package com.easysoft.framework.consult.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.consult.mapper.SysConsultationMapperExtd;
import com.easysoft.framework.consult.model.SysConsultation;
import com.easysoft.framework.consult.model.SysConsultationQuery;
import com.easysoft.framework.consult.model.SysConsultationView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by try on 2017/8/22.
 */
@Service("service.SysConsultationService")
public class SysConsultationService {

    @Autowired
    @Qualifier("mapper.SysConsultationMapperExtd")
    private SysConsultationMapperExtd sysConsultationMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysConsultation(SysConsultation sysConsultation){
        sysConsultation.setId(UUIDUtils.getUUID());
        sysConsultation.setCreateTime(new Date());
        return sysConsultationMapperExtd.insertSelective(sysConsultation);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysConsultation(String id){
        return sysConsultationMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysConsultation(SysConsultation sysConsultation){
        return sysConsultationMapperExtd.updateByPrimaryKeySelective(sysConsultation);
    }

    public SysConsultation selectSysConsultationById(String id){
        return sysConsultationMapperExtd.selectByPrimaryKey(id);
    }
    
    @DataSource(DataSource.SLAVE)
    public List<SysConsultationView> selectSysConsultationListByPage(SysConsultationQuery query, Page page){
        int maxRow = sysConsultationMapperExtd.selectCountSysConsultation(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysConsultationView>();
        }
        return sysConsultationMapperExtd.selectSysConsultationListByPage(query,page);
    }
}
